#include "otherwidget.h"
#include "models/command.h"

#include <QFormLayout>
#include <QLabel>

#include <models/syssettingmodel.h>

OtherWidget::OtherWidget(QWidget *parent)
    : QWidget{parent}
{
    QFormLayout* mainLayout = new QFormLayout(this);
    mainLayout->setContentsMargins(40*g_xScale,80*g_yScale,40*g_xScale,80*g_yScale);
    mainLayout->setSpacing(int(20*g_xScale));

    QLabel * pLabel = new QLabel(this);
    pLabel->setStyleSheet(QString("color:white;"
                "font:%1px '微软雅黑'").arg(18*g_xScale));
    pLabel->setText(tr("虚拟按键"));
     m_pVirtualBtn = new SwitchButton(this);
    m_pVirtualBtn->setFixedSize(60*g_xScale,30*g_yScale);
     mainLayout->addRow(pLabel,m_pVirtualBtn);
     m_pVirtualBtn->SetStatus(SysSettingModel::getInstance()->bShowVirtualBtns());

     pLabel = new QLabel(this);
     pLabel->setStyleSheet(QString("color:white;"
                                   "font:%1px '微软雅黑'").arg(18*g_xScale));
     pLabel->setText(tr("左摇杆xy运动"));
     m_pJoystickBtn=new SwitchButton(this);
     m_pJoystickBtn->setFixedSize(60*g_xScale,30*g_yScale);
     mainLayout->addRow(pLabel,m_pJoystickBtn);
     m_pJoystickBtn->SetStatus(SysSettingModel::getInstance()->bShowJoystickBtns());



     pLabel = new QLabel(this);
     pLabel->setStyleSheet(QString("color:white;"
                                   "font:%1px '微软雅黑'").arg(18*g_xScale));
     pLabel->setText(tr("数采落盘"));
     m_pTelemetryEdit = new QLineEdit(this);
     m_pTelemetryEdit->setStyleSheet(QString("QLineEdit {\
    border: 1px  solid  #48494E;\
    border-radius: 0px;\
    padding-left: 5px;\
    background-color: #232426; \
    color: #FFFFFF; \
    font:%1px '微软雅黑' \
    }").arg(18*g_xScale));
     m_pTelemetryEdit->setText(SysSettingModel::getInstance()->strTelemetryFolder());
     mainLayout->addRow(pLabel,m_pTelemetryEdit);
}

OtherWidget::~OtherWidget()
{
    if(isVisible())
    {
        saveData();
    }
}

void OtherWidget::hideEvent(QHideEvent *event)
{
    Q_UNUSED(event);
    saveData();
}

void OtherWidget::saveData()
{
    SysSettingModel::getInstance()->setOtherConfig(m_pVirtualBtn->GetStatus(),m_pJoystickBtn->GetStatus(),m_pTelemetryEdit->text());
}
